//
//  XSJCreateLiveRoomTableCell.m
//  XSJ
//
//  Created by yuanyuan he on 2020/5/9.
//  Copyright © 2020 apple. All rights reserved.
//

#import "XSJCreateLiveRoomTableCell.h"
#import "UIImageView+WebCache.h"

@interface XSJCreateLiveRoomTableCell()

@property (nonatomic, strong) UILabel* nameLabel;
@property (nonatomic, strong) UIImageView* iconView;
@property (nonatomic, strong) UILabel* titleLabel;
@property (nonatomic, strong) UIImageView* nextView;

@end

@implementation XSJCreateLiveRoomTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setup];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setup
{
    self.contentView.backgroundColor = ColorHex(0xffffff);
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.nextView];

    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.equalTo(self.contentView);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(75);
        make.right.mas_equalTo(self->_nextView.mas_left).offset(-5);
        make.centerY.equalTo(self.contentView);
    }];
    self.isShowTitleButton = NO;
    
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self->_nextView.mas_left).offset(-10);
        make.width.height.mas_equalTo(110);
        make.centerY.equalTo(self.contentView);
    }];
    self.isShowButton = NO;
    
    [_nextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.centerY.equalTo(self.contentView);
    }];
    self.isShowNextButton = YES;
    
    //下面横线
    UIView *hLineView = [[UIView alloc] init];
    hLineView.backgroundColor = ColorHex(0xffffff);
    [self.contentView addSubview:hLineView];
    
    [hLineView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.mas_equalTo(0);
         make.right.mas_equalTo(-0);
         make.bottom.equalTo(self.contentView);
         make.height.mas_equalTo(0.5f);
     }];
    
}

-(void)setTitle:(NSString *)title
{
    _title = title;
    _nameLabel.text = _title;
}

- (void)setName:(NSString *)name
{
    _name = name;
    _titleLabel.text = _name;
}

-(void)setIconURL:(NSString *)iconURL
{
    _iconURL = iconURL;
    [_iconView sd_setImageWithURL:[NSURL URLWithString:_iconURL]];
}

-(void)setIconName:(NSString *)iconName
{
    _iconName = iconName;
    _iconView.image = [UIImage imageNamed:_iconName];
    
    if (kStringIsEmpty(_iconName))
    {
        [_iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self->_nextView.mas_left).offset(-10);
            make.width.height.mas_equalTo(110);
            make.centerY.equalTo(self.contentView);
        }];
    }
    else
    {
        [_iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self->_nextView.mas_left).offset(-10);
            make.width.height.mas_equalTo(110);
            make.centerY.equalTo(self.contentView);
        }];
        _iconView.clipsToBounds = YES;
        _iconView.layer.cornerRadius = 1.0f;
    }
}

-(void)setIsShowButton:(BOOL)isShowButton
{
    _isShowButton = isShowButton;
    
    _iconView.hidden = !_isShowButton;
}

- (void)setIsShowTitleButton:(BOOL)isShowTitleButton
{
    _isShowTitleButton = isShowTitleButton;
    
    _titleLabel.hidden = !_isShowTitleButton;
}

- (void)setIsShowNextButton:(BOOL)isShowNextButton
{
    _isShowNextButton = isShowNextButton;
    
    _nextView.hidden = !_isShowNextButton;
}

- (UILabel *)nameLabel {
    if (_nameLabel == nil) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = ColorHex(0x696969);
        _nameLabel.font = [UIFont systemFontOfSize:14];
        [_nameLabel sizeToFit];
        [self.contentView addSubview:_nameLabel];
        //_nameLabel.verticalAlignment = VerticalAlignmentTop;//垂直居中
        _nameLabel.text = @"头像";
    }
    return _nameLabel;
}

- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc] init];
        _iconView.image = [UIImage imageNamed:@"Add"];
        _iconView.clipsToBounds = YES;
        _iconView.layer.cornerRadius = 10.0f;
    }
    return _iconView;
}

- (UILabel *)titleLabel {
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = ColorHex(0x696969);
        _titleLabel.font = [UIFont systemFontOfSize:12];
        _titleLabel.numberOfLines = 0;
        //右对齐
        _titleLabel.textAlignment = NSTextAlignmentRight;
        _titleLabel.text = @"陈宝宝老师";
    }
    return _titleLabel;
}

- (UIImageView *)nextView {
    if (_nextView == nil) {
        _nextView = [[UIImageView alloc] init];
        _nextView.image = [UIImage imageNamed:@"next"];
    }
    return _nextView;
}



@end
